class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int result = INT32_MAX;
        int sum = 0;
        int subLength = 0;
        for (int i=0; i<nums.size(); i++){
            sum = 0;
            for (int j=i; j<nums.size(); j++){
                sum += nums[j];
                if (sum >= target){
                    subLength = j - i + 1;
                    result = result < subLength ? result : subLength;
                    break;
                }
            }
        }
        return result == INT32_MAX ? 0 : result;
    }
};

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int result = INT32_MAX;
        int startIndex = 0;
        int sum = 0;
        int subLength = 0;
        for (int endIndex=0; endIndex<nums.size(); endIndex++){
            sum += nums[endIndex];
            while(sum >= target){
                subLength = endIndex - startIndex + 1;
                result = result < subLength ? result : subLength;
                sum -= nums[startIndex++];
            }                    
        }
        return result == INT32_MAX ? 0 : result;
    }
};